import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list: [], id: 0
  },
  mutations: {
    inits(state, arg) {
      state.list = arg
    },
    add(state, arg) {
      let id = ++state.id
      const obj = { id, txt: arg, ischx: Math.random() < 0.5 ? true : false }
      state.list.unshift(obj)
    },
    delete(state, id) {
      state.list.splice(state.list.findIndex(el => el.id == id), 1)
    }
  },
  getters: {
    complate(state) {
      return state.list.filter(el => !el.ischx)
    },
    uncomplate(state) {
      return state.list.filter(el => el.ischx)
    }
  },
  actions: {
  },
  modules: {
  }
})
